import tkinter as tk
import sys
sys.path.append('./')
import os

path = os.getcwd()
from chart_frame.src.utility.window_helper import center_window
  
def show_custom_dialog(parent):
    def on_closing():
        dialog.destroy()
        parent.focus_set()
    # 创建一个新的Toplevel窗口作为对话框  
    dialog = tk.Toplevel(parent)  
    dialog.title("自定义对话框")
  
    # 在对话框中添加一些控件  
    label = tk.Label(dialog, text="这是一个自定义的对话框")  
    label.pack(pady=10)  
  
    entry = tk.Entry(dialog)  
    entry.pack(pady=10)  
  
    def on_ok():  
        # 当用户点击“OK”按钮时，关闭对话框  
        print("用户输入了：", entry.get())  
        dialog.destroy()  
  
    ok_button = tk.Button(dialog, text="OK", command=on_ok)  
    ok_button.pack(pady=10)  

    center_window(dialog, 800, 700)
    dialog.protocol("WM_DELETE_WINDOW", on_closing)
    # 禁用父窗口，直到对话框关闭 
    parent.wait_window(dialog)
    dialog.destroy()
    parent.focus_set()
    #dialog.mainloop()
    
  
root = tk.Tk()  
root.title("自定义Dialog窗口示例")
center_window(root, 1024, 768)
  
# 创建一个按钮，点击时显示自定义对话框  
button = tk.Button(root, text="显示自定义对话框", command=lambda: show_custom_dialog(root))  
button.pack(pady=20, padx=20)  
  
# 运行主循环  
root.mainloop()
